package cn.com.yusys.yusp.admin.web.rest;


import cn.com.yusys.yusp.admin.domain.AdminSmProp;
import cn.com.yusys.yusp.admin.service.AdminSmPropService;
import cn.com.yusys.yusp.admin.service.impl.PropProviderServiceImpl;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.net.URISyntaxException;


/**
 * @version 1.0.0
 * @项目名称: yusp-admin
 * @类名称: AdminSmPropResource
 * @类描述: 系统参数
 * @功能描述:
 * @创建人: liaoxd@yusys.com.cn
 * @创建时间: 2017-12-27 18:00
 * @修改备注:
 * @修改记录: 修改时间    修改人员    修改原因
 * -------------------------------------------------------------
 * @Copyright (c) 2017宇信科技-版权所有
 */
@RestController
@RequestMapping("/api/adminsmprop")
public class AdminSmPropResource extends CommonResource<AdminSmProp, String> {

    @Autowired
    private AdminSmPropService adminSmPropService;
	@Autowired
	private PropProviderServiceImpl propCache;

    private final Logger log = LoggerFactory.getLogger(AdminSmPropResource.class);


    @Override
    protected CommonService getCommonService() {
        return this.adminSmPropService;
    }

    /**
     * @方法名称: deleteMult
     * @方法描述: 多个删除
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/deletes/{ids}")
    public ResultDto<Integer> deleteMult(@ApiParam(value = "Object Of PK id", required = true) @PathVariable String ids) {
        log.debug("REST request to delete Object : {}", ids);
        String[] id = ids.toString().split(",");
        int i;
        ResultDto<Integer> resultDto = new ResultDto<>();
        for (i = 0; i < id.length; i++) {
            resultDto = this.delete(id[i]);
            if (resultDto.getCode() != 0) {
                //删除出错,不再执行，抛出错误
                resultDto.setData(i);
                return resultDto;
            }
        }
        resultDto.setData(i);
        resultDto.setMessage("success");
		//先删除缓存在刷新缓存
        //stringRedisTemplate.delete("propInfo::findAllProp");
        propCache.cleanAllProp();
        propCache.findAllProp();
        return resultDto;

    }

    /**
     * @方法名称: updateSelective
     * @方法描述: 修改接口
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/updates")
    public ResultDto<Integer> updateSelective(@ApiParam(value = "Object", required = true) @RequestBody AdminSmProp t) throws URISyntaxException {
        log.debug("REST request to update Object : {}", t);

        ResultDto<Integer> resultDto = new ResultDto<>();
        try {
            int result = getCommonService().updateSelective(t);
            resultDto.setData(result);
            resultDto.setMessage("更新系统参数成功!");
        } catch (Exception e) {
            resultDto.setCode(500);
            resultDto.setMessage(e.getMessage());
        }
        return resultDto;
    }

}